﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tracy.DataModel;
using SharedLib;
using SharedLib.MessageFramework.Messages;
using SharedLib.MessageFramework.Handlers;

namespace Tracy.Handlers
{
    public class StartDownloadHandler : TaskMessageHandler
    {
        public static event EventHandler<GenericEventArgs<Resource>> ResourceSentToDownloader;
        protected override void ProcessMessage(TaskMessage msg)
        {
            if (msg != null && msg.Data != null && msg.Data is Resource)
            {
                Resource resourceToDownload = msg.Data as Resource;
                if (resourceToDownload != null)
                {
                    TracyFacade.Instance.DownloadManager.DownloadResource(resourceToDownload);
                    ResourceSentToDownloader.InvokeEvent(this, new GenericEventArgs<Resource>(resourceToDownload));
                }
                
            }
        }
    }
}
